package com.handpay.nocardpay.baselibrary.pay.unipay.model;

import android.content.Context;

import com.android.volley.Request;
import com.android.volley.VolleyError;
import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorParser;
import com.handpay.nocardpay.baselibrary.config.NoCardPayApi;
import com.handpay.nocardpay.baselibrary.http.HttpClientImpl;
import com.handpay.nocardpay.baselibrary.http.HttpHeadFactory;
import com.handpay.nocardpay.baselibrary.http.HttpListener;
import com.handpay.nocardpay.baselibrary.http.HttpRequest;
import com.handpay.nocardpay.baselibrary.logutils.HPLog;
import com.handpay.nocardpay.baselibrary.pay.unipay.model.bean.HistoryBankCardDelBean;
import com.handpay.nocardpay.baselibrary.utils.UrlUtils;

import java.util.HashMap;

/**
 * Created by lyang on 2017/8/25.
 */

public class HistoryBankCardDelModelImpl implements IBaseModel<HistoryBankCardDelBean> {
    private Context mContext;

    public HistoryBankCardDelModelImpl(Context context) {
        this.mContext = context;
    }

    @Override
    public void request(HashMap<String, Object> paramers, Class<HistoryBankCardDelBean> clzz,final OnRequestFinishedListener<HistoryBankCardDelBean> listener) {
        String url = UrlUtils.calculateAction(NoCardPayApi.Do_DeleteHistoryBankCardList);
        final HttpRequest request = new HttpRequest.Builder(url).setMethod(Request.Method.POST).addheader(HttpHeadFactory.createRequestHeaders(mContext)).addParam(paramers).build();
        HPLog.d(HPLog.YL_TAG, "url:" + url);
        HPLog.d(HPLog.YL_TAG, "paramers:" + paramers.toString());
        HPLog.d(HPLog.YL_TAG, "headers:" + HttpHeadFactory.createRequestHeaders(mContext).toString());
        HttpClientImpl.gsonRequest(clzz, request, new HttpListener<HistoryBankCardDelBean>() {
            @Override
            public void onSuccess(HistoryBankCardDelBean result) {
                if (result == null) {
                    listener.onError(new BaseErrorInfo("-1", mContext.getString(R.string.paser_error)));
                    return;
                }
                if (result.isRequstSuccess()) {
                    listener.onSuccess(result);
                } else {
                    listener.onError(new BaseErrorInfo(result.responseCode, result.errMessage));
                }
            }

            @Override
            public void onError(VolleyError error) {
                listener.onError(new BaseErrorParser(error));
            }
        }, NoCardPayApi.Do_DeleteHistoryBankCardList);
    }
}
